home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / perl / mac-perl / mcprl402.bin / Perl_src / macscripts / Helperl / Helperl
Encoding:
Text File  |  1992-12-21  |  1.2 KB  |  69 lines  |  [TEXT/MPS ]

  1. # Helperl - primitive help script if you don't or can't use MPW 411
  2.  
  3. # Voodoo to call Perl from the MPW Shell
  4.  
  5. Perl -Sx "{0}" {"Parameters"}; Exit
  6.  
  7. #!/usr/local/bin/perl
  8.  
  9. $help = $ENV{'PERLHELP'} || ":PerlHelp";
  10.  
  11. open(HELP, "<$help") || die "Couldn't open \"$help\". Don't forget to set PERLHELP.";
  12.  
  13. if ($#ARGV == -1) {
  14.     $topic = ask("Help topic ?", "PerlHelp") || "PerlHelp";
  15.     $help{$topic} = 1;
  16. } else {
  17.     foreach $i (@ARGV) {
  18.         $help{$i} = 1;
  19.     }
  20. }
  21.  
  22. main: while (<HELP>) {
  23.     next unless (/^╛KY\s+(\w+)/);
  24.  
  25.     # Are we interested in one of the keywords ? 
  26.     
  27.     $found = 0;
  28.     for (;;) {
  29.         $found = 1 if ($help{$1});
  30.         last main unless ($_ = <HELP>);
  31.         last if (/^╛/);
  32.         /(\w+)/;
  33.     }
  34.     redo main unless ($found);
  35.     
  36.     help: for (;;) {
  37.         if (/^╛C\s+(.*)/) {
  38.             print "$1\n";
  39.             while ($_ = <HELP>) {
  40.                 redo help if (/^╛/);
  41.                 print;
  42.             }
  43.             last main;
  44.         } elsif (/^╛KL\s+(\S+)/) {
  45.             do {
  46.                 push(@words, $1);
  47.             }╩while (($_ = <HELP>) && !/^╛/ && /(\S+)/);
  48.             $col = 0;
  49.             foreach $i (@words) {
  50.                 printf "%-30s", $i;
  51.                 print "\n" unless (++$col % 3);
  52.             }
  53.             print "\n";
  54.             
  55.             redo help if (defined $_);
  56.             
  57.             last main;
  58.         } elsif (/^╛KY/) {
  59.             print "\n\n";
  60.             redo main;
  61.         } else {
  62.             while (($_ = <HELP>)) {
  63.                 redo help if (/^╛/);
  64.             }
  65.             last main;
  66.         }
  67.     }
  68. }
  69.